<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>成绩管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#title").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
                    loading('正在提交，请稍等...');
                    form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/cms/userCourseScore/">成绩列表</a></li>
		<li class="active"><a href="${ctx}/cms/userCourseScore/form?id=${userCourse.id}&courseId=${userCourse.courseId}">成绩<shiro:hasPermission name="
		cms:userCourseScore:edit">${not empty userCourse.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="cms:userCourseScore:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="userCourse" action="${ctx}/cms/userCourseScore/save" method="post" class="form-horizontal">
		<sys:message content="${message}"/>
        <div class="control-group">
            <label class="control-label">学员选择:</label>
            <div class="controls">
                <ol id="userSelectList"></ol>
                <a id="userSelectButton" href="javascript:" class="btn">选择学员</a>
                <script type="text/javascript">
                    $("#userSelectButton").click(function(){
                        top.$.jBox.open("iframe:${ctx}/cms/userCourse/selectList?pageSize=8", "选择学员",$(top.document).width()-220,$(top.document).height()-180,{
                            buttons:{"确定选择":"ok", "关闭":true},submit:function(v, h, f){
                                var selectedUserFromBox = h.find("iframe")[0].contentWindow.selectedUserFromBox;
                                $("#id").val(selectedUserFromBox[0][0]);
                                $("#name").val(selectedUserFromBox[0][1]);
                            }, loaded:function(h){
                                var userSelect=[];
                                userSelect.push($("#id").val(),$("#name").val());
                                h.find("iframe")[0].contentWindow.parentUserSelect=userSelect;
                                $(".jbox-content", top.document).css("overflow-y","hidden");
                            }
                        });
                    });
                </script>
            </div>
        </div>
		<div class="control-group">
			<label class="control-label">学员ID：</label>
			<div class="controls">
				<form:input id="id" path="id" htmlEscape="false" maxlength="200" class="input-xlarge measure-input required" readonly="true"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">学员昵称：</label>
			<div class="controls">
				<form:input id="name" path="name" htmlEscape="false" maxlength="255" class="input-xlarge " readonly="true"/>
			</div>
		</div>
        <div class="control-group">
            <label class="control-label">课程选择:</label>
            <div class="controls">
                <form:hidden id="articleDataRelation" path="courseId" htmlEscape="false" maxlength="200" class="input-xlarge"/>
                <ol id="articleSelectList"></ol>
                <a id="relationButton" href="javascript:" class="btn">考试课程</a>
                <script type="text/javascript">
                    var articleSelect = [];
                    function articleSelectAddOrDel(id,title){
                        var isExtents = false, index = 0;
                        for (var i=0; i<articleSelect.length; i++){
                            if (articleSelect[i][0]==id){
                                isExtents = true;
                                index = i;
                            }
                        }
                        if(isExtents){
                            articleSelect.splice(index,1);
                        }else{
                            articleSelect.push([id,title]);
                        }
                        articleSelectRefresh();
                    }
                    function articleSelectRefresh(){
                        $("#articleDataRelation").val("");
                        $("#articleSelectList").children().remove();
                        for (var i=0; i<articleSelect.length; i++){
                            $("#articleSelectList").append("<li>"+articleSelect[i][1]+"&nbsp;&nbsp;<a href=\"javascript:\" onclick=\"articleSelectAddOrDel('"+articleSelect[i][0]+"','"+articleSelect[i][1]+"');\">×</a></li>");
                            if(i == articleSelect.length - 1){
                                $("#articleDataRelation").val($("#articleDataRelation").val()+articleSelect[i][0]);
                            }else{
                                $("#articleDataRelation").val($("#articleDataRelation").val()+articleSelect[i][0]+",");
                            }
                        }
                    }
                    $.getJSON("${ctx}/cms/article/findByIds",{ids:$("#articleDataRelation").val()},function(data){
                        for (var i=0; i<data.length; i++){
                            articleSelect.push([data[i][1],data[i][2]]);
                        }
                        articleSelectRefresh();
                    });
                    $("#relationButton").click(function(){
                        top.$.jBox.open("iframe:${ctx}/cms/article/selectList?pageSize=8", "考试课程",$(top.document).width()-220,$(top.document).height()-180,{
                            buttons:{"确定选择":"ok", "关闭":true},submit:function(v, h, f){
                                var selectedArticleFromBox = h.find("iframe")[0].contentWindow.selectedArticleFromBox;
                                for (var i = 0; i<selectedArticleFromBox.length; i++) {
                                    articleSelectAddOrDel(selectedArticleFromBox[i][0],selectedArticleFromBox[i][1]);
                                }
                            }, loaded:function(h){
                                h.find("iframe")[0].contentWindow.parentArticleSelect=articleSelect;
                                $(".jbox-content", top.document).css("overflow-y","hidden");
                            }
                        });
                    });
                </script>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">学习成绩：</label>
            <div class="controls">
                <form:input path="courseScore" htmlEscape="false" maxlength="5" class="input-xlarge "/>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">考试时间:</label>
            <div class="controls">
                <input id="examDate" name="examDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
                       value="<fmt:formatDate value="${userCourse.examDate}" pattern="yyyy-MM-dd HH:mm:ss"/>"
                       onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
            </div>
        </div>
		<div class="form-actions">
			<shiro:hasPermission name="cms:userCourseScore:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>